<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAdminUserTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('admin_user', ['comment'=>'用户账号表'])
            ->addColumn(Column::unsignedInteger('pid')->setDefault(0)->setComment('上级'))
            ->addColumn(Column::integer('user_type')->setDefault(1)->setComment('用户类型'))
            ->addColumn(Column::string('nickname', 64)->setNullable()->setComment('昵称'))
            ->addColumn(Column::string('username', 32)->setDefault('')->setComment('用户名'))
            ->addColumn(Column::string('password', 64)->setDefault('')->setComment('密码'))
            ->addColumn(Column::string('email', 64)->setDefault('')->setComment('邮箱'))
            ->addColumn(Column::tinyInteger('email_bind')->setDefault(0)->setComment('邮箱'))
            ->addColumn(Column::string('mobile', 16)->setDefault('')->setComment('手机号'))
            ->addColumn(Column::tinyInteger('mobile_bind')->setDefault(0)->setComment('手机验证'))
            ->addColumn(Column::string('avatar')->setDefault('')->setComment('头像'))
            ->addColumn(Column::unsignedInteger('score')->setDefault(0)->setComment('积分'))
            ->addColumn(Column::decimal('money')->setDefault(0)->setComment('余额'))
            ->addColumn(Column::string('reg_ip', 20)->setDefault('')->setComment('注册IP'))
            ->addColumn(Column::string('reg_type', 15)->setDefault('')->setComment('注册方式'))
            ->addColumn(Column::string('invite_code', 32)->setDefault('')->setComment('邀请码'))
            ->addColumn(Column::integer('create_time')->setNullable()->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setNullable()->setComment('修改时间'))
            ->addColumn(Column::integer('delete_time')->setNullable()->setComment('删除时间'))
            ->addColumn(Column::tinyInteger('status')->setDefault(0)->setComment('状态'))
            ->create();
    }
}
